<template>
<div>
<div class="main">
      <div class="title">创建班级</div>
     <Form :model="roster" label-position="left"  :label-width="100">
        <FormItem label="班级名称">
            <Input v-model="roster.class_name" placeholder="请输入班级名称" required></Input>
        </FormItem>
        <FormItem label="班级描述">
            <Input v-model="roster.desc" placeholder="请输入班级描述" required></Input>
        </FormItem>
        <div class='btn'>
            <Button type="primary" @click="add">创建班级</Button>
        </div>
      </Form>
  </div>
</div>

</template>

<script>
import api from '../../api/index.js'
import {mapState} from 'vuex'
  export default {
    name:'employeeAdd',
    data () {
      return {
        roster:{
          class_name:null,
          desc:null,
          creater:null,
        }
      };
    },
    computed:{
      ...mapState([
        'user'
      ])
    },
    mounted() {

    },
    methods: {
      add(){
        if(!this.roster.class_name){
          this.$Message.warning('请您输入班级名称');
          return;
        }else if(!this.roster.desc){
          this.$Message.warning('请您输入班级描述');
          return;
        }else {
          this.roster.creater=this.user.user_number;
          api.addClass(this.roster).then(res=>{
            if(res.status==1){
              this.$Message.success('创建班级成功');
              this.roster={
                class_name:null,
                desc:null,
                creater:null
              }
            }
          })
        }
      }
    }
  }
</script>
<style lang='scss' scoped>

.main{
    width: 50%;
    margin: 0 auto;
    font-size: 16px;
    .title{
        text-align: center;
        font-size: 20px;
        margin-bottom: 10px;
    }
    .ivu-form-item{
        margin-bottom: 14px;

    }
    .btn{
       margin-top: 40px;
        text-align: center;
    }
}



</style>
